﻿#include "pch.h"

//分割文本A
int WoHaperStringSplitWithStlA(std::string &str, std::string pattern, std::vector<std::string>&r)
{
    if ("" == str)
    {
        return 0;
    }
    std::string strs;
    strs.append(str).append(pattern);
    size_t pos = strs.find(pattern);
    size_t size = strs.size();
    while (pos != std::string::npos)
    {
        std::string x = strs.substr(0, pos);
        r.push_back(x);
        strs = strs.substr(pos + 1, size);
        pos = strs.find(pattern);
    }
    return r.size();
}
//分割文本A
int WoHaperStringSplitWithStlA_view(std::string_view str, std::string_view pattern, std::vector<std::string>& r)
{
    if ("" == str)
    {
        return 0;
    }
    std::string strs;
    strs.append(str).append(pattern);
    size_t pos = strs.find(pattern);
    size_t size = strs.size();
    while (pos != std::string::npos)
    {
        std::string x = strs.substr(0, pos);
        r.push_back(x);
        strs = strs.substr(pos + 1, size);
        pos = strs.find(pattern);
    }
    return r.size();
}
void WoHaperStringTrimA(std::string str, std::string& r)
{
    r = str;
	if (!r.empty())
	{
        r.erase(0, r.find_first_not_of(' '));
        r.erase(r.find_last_not_of(' ') + 1);
    }
    else {
        r = "";
    }
}